package com.tech.koufu.ui.adapter;

import java.util.ArrayList;
import java.util.Map;

import com.tech.koufu.R;
import com.tech.koufu.model.Stock;
import com.tech.koufu.ui.adapter.PostionsStocksAdapter.ViewHolder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 
 * @ClassName: QueryStockListAdapter
 * @Description: TODO(股票查询时下拉列表)  
 * @author 123
 * @date 2015年4月15日 下午8:52:49
 */
public class QueryStockListAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<Stock> lst;
	private LayoutInflater mInflater;
	public QueryStockListAdapter(Context context , ArrayList<Stock> lst){
		this.context = context;
		this.lst = lst;
		mInflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() { 
		if(lst!=null){
			return lst.size();
		}else{
			return 0;
		}
	}

	@Override
	public Object getItem(int position) { 
		if(lst!=null){
			return lst.get(position);
		}else{
			return null;
		}
	}

	@Override
	public long getItemId(int position) { 
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) { 
		ViewHolder holder = null;   
        if(convertView == null)  
        {  
        	 holder = new ViewHolder();   
             convertView = mInflater.inflate(R.layout.lv_query_stock, parent,false);  
             holder.txtView = (TextView) convertView.findViewById(R.id.txt_name);
             convertView.setTag(holder);  
        }else{
        	holder = (ViewHolder)convertView.getTag();  
        }
        Stock stock = (Stock) getItem(position);
        holder.txtView.setText(stock.name+"("+stock.code+")");
		return convertView;
	}
	static class ViewHolder {
		public TextView txtView;
	}
}
